<extend name="Public/header" />

<block name="main">
    <div class="col-lg-12">
        <div class="panel panel-default">
            <div class="panel-heading">
                商品列表 Tables
            </div>
            <div class="panel-body">
                <div id="dataTables-example_wrapper" class="dataTables_wrapper form-inline dt-bootstrap no-footer">
                    <div class="row">
                        <form role="form" action="{:U('index')}" method="get" enctype="multipart/form-data">
                            <div class="col-sm-6">
                                <div class="form-group">
                                    <label>商家</label>
                                    <select name="bid" class="form-control">
                                        <option value="">请选择</option>
                                        <foreach name="list" item="val">
                                            <option value="{$val.bid}">{$val.bname}</option>
                                        </foreach>
                                    </select>
                                </div>
                            </div>
                            <div class="form-group input-group">
                                <input type="text" class="form-control" name="selname" value="关键字">
                                <span class="input-group-btn">
                                                <button type="submit" class="btn btn-default" ><i class="fa fa-search"></i>
                                                </button>
                                            </span>
                            </div>
                        </form>
                    </div>
                    <br>

            <!-- /.panel-heading -->
            <div class="panel-body">
                <table width="100%" class="table table-striped table-bordered table-hover" id="">
                    <thead>
                    <tr>
                        <!--   <th>No.</th> -->
                        <th>图片</th>
                        <th>名称</th>
                        <th>所属分店</th>
                        <th>分类</th>
                        <th>现价</th>
                        <th>会员</th>
                        <th>售出</th>
                        <th>库存</th>
                        <th>状态</th>
                        <th>时间</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <foreach name="list" item="val">
                        <tr class="odd gradeX">
                            <!--  <td>{++$i}</td> -->
                            <td><img width="100" src="__ROOT__{$val.img}" alt=""></td>
                            <td>{$val.name}</td>
                            <td>{$val.bname}</td>
                            <td>{$val.tname}</td>
                            <td>{$val.price}</td>
                            <td>{$val.pprice}</td>
                            <td>{$val.sold}</td>
                            <td>{$val.stock}</td>
                            <td class="center qj">{$val['state'] == 1 ? '启用' : '禁用'}</td>
                            <td class="center">{:date('Y-m-d H:i:s',$val['time'])}</td>
                            <td class="center">
                                <!--
                                   <a href="{:U('edit',['id'=>$val['id']])}" class="btn btn-outline btn-primary">编辑</a> <br> -->
                                <a href="javascript:void (0)" class="btn btn-outline btn-success" onclick="qj(this,{$val['id']})">{$val['state'] == 1 ? '隐藏' : '启用'}</a> <br>
                                <a href="{:U('del',['id'=>$val['id']])}"  class="btn btn-outline btn-danger" >删除</a><br>
                                <a href="{:U('pic',['id'=>$val['id']])}" class="btn btn-outline btn-warning">图片({$val.num})</a> <br>
                            </td>
                        </tr>
                    </foreach>
                    </tbody>
                </table>
                <!-- /.table-responsive -->
                <div class="row"><div class="col-sm-6"></div>
                    <div class="col-sm-6">
                        <div class="dataTables_paginate paging_simple_numbers" id="dataTables-example_paginate">
                            <div class="pages" style="margin: 0px auto;text-align: center;">
                                {$page}
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!-- /.panel-body -->
        </div>
        <!-- /.panel -->
    </div>

</block>
<block name="js">
    <script>
        function qj(tha,id) {
            $.ajax({
                type: 'POST',
                data:{id:id},
                url: '{:U("gqj")}',
                success: function(dat){
                    console.dir(dat);
                    dat = JSON.parse(dat);
                    alert(dat.message)
                    if(dat.state == 1)
                    {
                        $(tha).html('隐藏')
                        $(tha).parent().parent().find('.qj').html('启用')
                    }else if(dat.state == 2){
                        $(tha).html('启用')
                        $(tha).parent().parent().find('.qj').html('隐藏')
                    }
                },
                error:function () {
                    alert('系统错误')
                }
            })
        }
    </script>
</block>